package com.shenhaofeng.app.navigation;

import android.support.v4.widget.DrawerLayout;
import android.view.View;

/**
 * 本质是{@link DrawerLayout}的实现类,发送一个延时Intent的同时监听DrawerLayout的关闭事件,一旦关闭立即发送延时意图
 * Created by Administrator on 2016/5/5.
 */
public class DrawerCloseEvent implements DrawerLayout.DrawerListener {

    private DrawerLayout drawerLayout;
    private DrawerClosePendingIntent drawerClosePendingIntent;


    public DrawerCloseEvent(DrawerLayout drawerLayout) {
        this.drawerLayout = drawerLayout;
    }


    @Override
    public void onDrawerSlide(View drawerView, float slideOffset) {

    }


    @Override
    public void onDrawerOpened(View drawerView) {

    }


    @Override
    public void onDrawerClosed(View drawerView) {
        if (drawerClosePendingIntent != null) {
            drawerView.getContext().startActivity(drawerClosePendingIntent.onSendIntent());
        }
        drawerClosePendingIntent = null;
    }


    @Override
    public void onDrawerStateChanged(int newState) {

    }


    /**
     * 关闭抽屉并且在关闭后发送Intent
     * @param pendingIntent
     */
    public void closeAndSendPendingIntent(DrawerClosePendingIntent pendingIntent) {
        drawerClosePendingIntent = pendingIntent;
        drawerLayout.closeDrawers();
    }
}
